package com.amit.services;

import com.amit.entities.StudentEntity;
import com.amit.repositories.StudentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: AD
 * Date: 08/01/13
 * Time: 09:39
 */

@SuppressWarnings({"SpringJavaAutowiringInspection", "UnusedDeclaration"})
@Service
public final class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentRepository repository;

    public StudentServiceImpl() {

    }

    @Override
    @Transactional
    public Long addStudent(String firstName, String lastName) {
        return repository.save(new StudentEntity(null, firstName, lastName)).getId();
    }

    @Override
    public void removeStudent(Long studentId) {
        repository.delete(studentId);
    }

    @Override
    @Transactional
    public List<StudentEntity> readAllStudents() {
        return repository.findAll();
    }

    @Override
    @Transactional
    public StudentEntity readStudent(Long id) {
        return repository.findOne(id);
    }

}
